<template>
    <div class="taskMoudle">
        <div class="task-header">
            <span class="taskTxt" v-if="infoData">当前任务：{{infoData.task_name}} {{infoData.task_status_str}} ({{infoData.sub_set_name}} {{infoData.file_name}})</span>
            <el-button size="small" class="task-switch" @click="$router.push({path:'/TaskMangeList'})">切换任务</el-button>
        </div>
        <div class="content">
            <el-col :span="3" >
                <v-tree v-on:task-tree="taskTree" :infoData='infoData'></v-tree>
            </el-col>
             <el-col :span="21">
                <div class="task-screen clearfix">
                    <div class="task-screen-2 pull-fl">
                        <el-button size="small" :disabled='queryData.flag == 4' @click="handleAuditResult(false)">标记为通过</el-button>
                        <el-button size="small" :disabled='(StatisticsData?StatisticsData.rejected_count>0:true) || (queryData.flag ==4)' @click="handleAuditResult(true)">通过任务</el-button>
                        <span class="verticalLine" ></span>
                        <el-button size="small" :disabled='queryData.flag == 4' type="primary" @click="rejectResult(false)" >标记为驳回</el-button>
                        <el-button size="small" :disabled='queryData.flag == 4' type="primary"  @click="rejectResult(true)" >驳回任务</el-button>
                    </div>
                    <div class="task-screen-3 pull-fl">
                        <span v-html="state==1?'待审核的数据中：':'待处理的数据中：'"></span>
                        <span>
                            新增{{infoData?infoData.extend_info.audit_info.new_data:0}}条,
                            修改{{infoData?infoData.extend_info.audit_info.modify_data:0}}条,  
                            删除{{infoData?infoData.extend_info.audit_info.delete_data:0}}条,
                        </span>
                        <span class="DangerColor">，其中异常数据{{infoData?infoData.extend_info.audit_info.abnormal_data:0}}条</span>
                    </div>
                    <span class="task-screen-4 pull-fr"> 标记驳回{{StatisticsData?StatisticsData.rejected_count:0}}条</span>
                    <span class="task-screen-4 pull-fr"> 标记通过{{StatisticsData?StatisticsData.audited_count:0}}条</span>
                    <span class="task-screen-4 pull-fr"> 待审核的数据{{StatisticsData?StatisticsData.to_be_audited_count:0}}条</span>
                </div>
                <div class="task-content" id="taskContent">
                    <el-col :span="24" class="task-map">
                        <v-map :ToExamine='true'></v-map>
                    </el-col>
                    <el-col :span="24" class="task-table">
                        <div class="table-drag">
                            <div id="line"></div>
                             <div id="box">
                                <v-table :queryData='queryData'></v-table>
                            </div> 
                        </div>
                    </el-col>
                    <div class="task-dropdown-menu">
                        <p class="menu1"><em>当前显示层：</em>
                            <span v-for="(item,index) in getCheckedNodes" :key="index">{{item.item_name+','}}</span>
                        </p>
                        <p class="menu2"><em>数据量：</em><span>{{pagination?pagination.total:0}}条</span></p>
                        <p class="menu3">
                            <em>显示数量：</em>
                            <el-input-number v-model="NewDataList.page_size" @change="changePageSize" :min="1" :max="pagination?pagination.total:1" label="输入条数"></el-input-number>
                        </p>
                        <div class="btn">
                            <el-button size="mini" @click="NextPage">显示下{{NewDataList.page_size}}条</el-button>
                            <el-button size="mini" @click="prevPage">显示上{{NewDataList.page_size}}条</el-button>
                        </div>
                    </div>
                </div>
            </el-col>
        </div>

        <el-dialog title="驳回原因" :visible.sync="dialogReject" width="30%" >
            <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入驳回原因"
                v-model="rejectTextarea">
            </el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogReject = false">取 消</el-button>
                <el-button type="primary" @click="handleAddTaskList()">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import Tree from '../common/TaskModule/tree.vue';
import Map from '../common/TaskModule/map.vue';
import Table from '../common/TaskModule/table.vue';
import AuditMangeService from '../../services/AuditMangeService.js';
import TaskMangeService from '../../services/TaskMangeService.js';
import bus from '../common/bus.js';
import gcoord from 'gcoord';
export default {
   components: {
       'v-tree':Tree,
       'v-map':Map,
       'v-table':Table,
    },
 
    data() {
        return {
            AuditMangeService:new AuditMangeService(),
            TaskMangeService:new TaskMangeService(),
            loading:true,  
            infoData:null,
            StatisticsData:null,
            dialogReject:false,
            auditTaskData:[],
            rejectTextarea:'',
            taskFlag:null,
            pagination:{},
            selectTaskDataList:[],
            getCheckedNodes:[],
            queryData:this.$route.query,
            state:0, 
            NewDataList:{
                id:322,
                check_status:null,
                audit_status:null,
                page_index: 1,
                page_size: 10,
                geo_layers: []
            },
        }
    },
    created() {
        // this.taskDetail();
        this.taskStatistics()
    },
    computed:{
        
    },
    mounted() {
        let _this=this;
        this.tableDrag();
        bus.$on('load', function (content) {
            _this.loading=content
        })
         //点击左右鼠标；
        bus.$on('LeftJson', (res)=>{
            this.auditTaskData = res;
        });
        bus.$on('RightJson', (res)=>{
            let flag = this.queryData?this.queryData.flag == 3:null; 
            if(flag){
                this.addRightTask(res)
            }else{ 
                this.$message.warning('查看状态请勿操作')
            }
        });
        // 操作加入通过列表
        bus.$on('markTaskData', (res)=>{
            this.addTaskListApi(res)
        });
        //select框选择；
        bus.$on('SelectOptions', (res)=>{
            this.NewDataList.check_status = res.check_status;
            this.NewDataList.audit_status = res.audit_status;
            this.NewDataList.page_index = 1;
            this.NewList()
        });
    },
    methods:{
        //待处理数据加入通过或者驳回清单中API
        async addTaskListApi(paramData){
            let res = await this.AuditMangeService.add_taskList(paramData)
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.taskStatistics();
                this.NewList()
            } else {
                this.$message.error(res.msg)
            }
        },

        //任务通过审核API
        async taskAdoptApi(paramData){
            let res = await this.AuditMangeService.task_adopt(paramData);
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.$router.push({path:'/AuditList'})
            } else {
                this.$message.error(res.msg)
            }
        },

        //加入驳回清单API
        async taskOverruledApi(paramData){
            let res = await this.AuditMangeService.task_overruled(paramData);
            if (res.code == 200) {
                this.$router.push({path:'/AuditList'})
                this.$message.success(res.msg);
            } else {
                this.$message.error(res.msg)
            }
        },

        //驳回原因；
        rejectResult(flag){
            this.dialogReject = true;
            this.taskFlag = flag;
        },

        //处理待处理数据驳回逻辑
        handleAddTaskList(){
            let paramData = {};
            if(this.taskFlag){
                //任务驳回逻辑；
                paramData.task_id = Number(this.queryData.task_id);
                paramData.remark = this.rejectTextarea;
                this.taskOverruledApi(paramData) 
            }else{
                paramData.data_s = [{id:this.auditTaskData.id,remark:this.rejectTextarea}];
                paramData.adopt=106030;      
                this.addTaskListApi(paramData)
            }
            this.rejectTextarea = ''
            this.dialogReject = false;
        },
        //右键添加驳回逻辑；
        addRightTask(res){
            let paramData = {};
            if(res.submitted){
                paramData.data_s = [{id:res.id,remark:null}];
                paramData.adopt=106020;    
                this.addTaskListApi(paramData);  
            }else{
                this.dialogReject = true;    
                this.taskFlag =false;
                this.auditTaskData = res;
            }
      
            // paramData.data_s = [{id:this.res.id,remark:this.rejectTextarea}];
        },
        //处理审核通过逻辑;
        handleAuditResult(flag){
            let paramData ={};
            if(flag){
                paramData.task_id = Number(this.queryData.task_id);
                this.taskAdoptApi(paramData);  
            }else{
                paramData.data_s = [{id:this.auditTaskData.id,remark:null}];
                paramData.adopt=106020;    
                this.addTaskListApi(paramData);  
            }
        },
        
        //获取数据处理的统计情况；
        async taskStatistics(){
            let paramData ={id:Number(this.queryData.task_id)};
            let res = await this.TaskMangeService.task_statistics(paramData)
            if(res.code==200){
                this.StatisticsData = res.data
            }else{
                this.$message.error(res.msg);
            }
        },

        //获取任务详情
        async taskDetail(){
            let paramData ={id:Number(this.queryData.task_id),for_audit:true};
            let res = await this.TaskMangeService.task_detail(paramData)
            if(res.code==200){
                this.infoData = res.data;
            }else{
                this.$message.error(res.msg);
            }
        },

        //页面显示个数
        changePageSize(val){
            this.NewDataList.page_size=val;
            this.NewList();
        },

        //下一页；
        NextPage(){
            if(this.pagination.page_index<this.pagination.page_count){
                this.NewDataList.page_index += 1;
                this.NewList();
            }else{
                this.$message.warning('已经是最后一页了')
            }
        },
        
        //显示上一页
        prevPage(){
            if(this.pagination.page_index>1){
                this.NewDataList.page_index -= 1;
                this.NewList();
            }else{
                this.$message.warning('没有上一页了')
            }
        },
        taskTree(data,CheckedNodes){
          this.getCheckedNodes=CheckedNodes;
          this.NewDataList.geo_layers=data;
          this.NewList();
        },

        //返回新数据列表
        async NewList(){
            this.NewDataList.id=Number(this.queryData.task_id);
            this.NewDataList.for_audit=true;
            let res = await this.TaskMangeService.task_contents(this.NewDataList);
            if(res.code == 200){
                this.pagination = res.data.pagination;
                bus.$emit('pagination',res.data.pagination)
                if(res.data.list[0]!=undefined){
                    let geoJson=JSON.parse(JSON.stringify(res.data.list[0].geo_json));
                    var result = gcoord.transform(geoJson, gcoord.WebMercator,gcoord.BD09);
                    this.TemporaryPoint=this.DataContrast(result.coordinates,result.type);
                }else{
                    this.TemporaryPoint=[] 
                }
                bus.$emit('Treedata', this.gcoordInfo(res.data.list),this.TemporaryPoint);
            }
        },
        //数据类型对比
        DataContrast(cont,type){
            var x=[];
            switch (type)
            {
            case 'Point':x=[cont[0],cont[1]];
            break;
            case 'MultiLineString':x=[cont[0][0][0],cont[0][0][1]];
            break;
            case 'MultiPolygon':x=[cont[0][0][0][0],cont[0][0][0][1]];
            break;
						case 'LineString':x=[cont[0][0],cont[0][1]];
						break;
            }
            return x;
        },
        //地图坐标转化
        gcoordInfo(content){
            this.NewData=[];
            if(content!=[]){
            for(let i=0;i<content.length;i++){
                var newLayer=content[i].geo_layer;
                var newGeojson = content[i].geo_json;
                gcoord.transform( newGeojson, gcoord.WebMercator,gcoord.BD09 );
                let Maplist={
                ColorProperty:this.ColorContrast(content[i]),
                geo_layer:newLayer,
                Point:newGeojson.coordinates,
                type:content[i].geo_json.type,
                rest:content[i]
                }
                this.NewData.push(Maplist)
            }
            }
            return this.NewData
        },

        ColorContrast(data){
            var x='';
            if(data.submitted==false){
                x=106001;
            }else if(data.submitted==true&&data.audit_status==106010){
                x=106010;
            }else if(data.submitted==true&&data.audit_status==106020){
                x=106020;
            }else if(data.submitted==true&&data.audit_status==106030){
                x=106030;
            }
            return x;
        },
        tableDrag(){
            let _this=this;
            _this.$comPlugIn.dragBoxInfo('box','line','taskContent')
        }

    },
}
</script>
<style>
  @import '../../../static/css/task-moudel.css';
</style>







